package com.woniu.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniu.entity.Result;
import com.woniu.entity.vo.CommentVO;
import com.woniu.pojo.Comment;
import com.woniu.pojo.Like;
import com.woniu.pojo.Message;
import com.woniu.pojo.User;
import com.woniu.service.ICommentService;
import com.woniu.service.ILikeService;
import com.woniu.service.IMessageService;
import com.woniu.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Title
 * @Author 武术有栖
 * @Description:
 */
@Controller
@Api(tags = "评论模块")
@RequestMapping("/comment")
@Slf4j
public class CommentController extends BaseController {
    @Autowired
    private ICommentService commentService;
    @Autowired
    private ILikeService likeService;

    @GetMapping("/listRoot1/{trainingId}")
    @ApiOperation("获取评论列表以时间排序thymeleaf")
    public String listCommentByTime(Model model, @PathVariable String trainingId) {
        List<CommentVO> commentVOList = commentService.listRootCommentByTime(trainingId);
        model.addAttribute(commentVOList);
        return "comment";
    }
    @GetMapping("/listRoot2/{trainingId}")
    @ApiOperation("获取评论列表以点赞排序thymeleaf")
    public String listCommentByLike(Model model, @PathVariable String trainingId) {
        List<CommentVO> commentVOList = commentService.listRootCommentByLike(trainingId);
        model.addAttribute(commentVOList);
        return "comment";
    }

    @GetMapping("/list/time/{trainingId}")
    @ApiOperation("获取评论列表以时间排序")
    @ResponseBody
    public Result listCommentByTime(@PathVariable String trainingId) {
        List<CommentVO> commentVOList = commentService.listRootCommentByTime(trainingId);
        return toDataResult(commentVOList);
    }

    @GetMapping("/list/like/{trainingId}")
    @ApiOperation("获取评论列表以点赞数排序")
    @ResponseBody
    public Result listCommentByLike(@PathVariable String trainingId) {
        List<CommentVO> commentVOList = commentService.listRootCommentByLike(trainingId);
        return toDataResult(commentVOList);
    }

    @PostMapping("/addLike")
    @ApiOperation("点赞")
    @ResponseBody
    public Result like(Like like) {
       likeService.add(like);
        return success();
    }

    @PostMapping("/addComment")
    @ApiOperation("评论")
    @ResponseBody
    public Result comment(Comment comment) {
        commentService.add(comment);
        return success();
    }

}
